package tests;

import junit.framework.*;
import java.util.ArrayList;
import java.util.Date;
import java.text.*;

import org.junit.Before;
import org.junit.Test;

import Model.AddTaskCommand;
import Model.Task;

/**
 * JUnit test case for AddTaskCommandTest
 */

public class AddTaskCommandTest extends TestCase {
	//declare reusable objects to be used across multiple tests
	 AddTaskCommand t1;
	 ArrayList<Task> arrList=null;
	 Date utilDate = new Date();
	 Task newtask;
	 
	public AddTaskCommandTest(String name) {
		super(name);
	}

	@Before
	protected void setUp() {
	//define reusable objects to be used across multiple tests
	DateFormat df = new SimpleDateFormat("dd/MM/yyyy");
	    
	try { 

	 utilDate = df.parse("15/11/2011");
	 newtask = new Task("Task 1",utilDate,"Type 2");
     arrList = new ArrayList<Task>();
	 
	 t1 = new AddTaskCommand(arrList);
	 
			} 
			
			catch (ParseException e) {
				e.printStackTrace();
			}
	}

	@Test
	public void testAddTaskCommandConstructor() {

		AddTaskCommand var0 = new AddTaskCommand(arrList);
		
		assertNotNull("Object is created",var0);
		
	}
	
	@Test
	public void testExecute() {

		AddTaskCommand var0 = new AddTaskCommand(arrList);
		String var1 = "Task 1";
		Date var2 = utilDate;
		String var3 = "Periodic";
		String var4 = "Frequency";
		var0.execute(var1, var2, var3, var4);
		assertEquals(arrList.size(),1);
		assertEquals(arrList.get(0).getName(),var1);
		assertEquals(arrList.get(0).getDueDate(),var2);
		assertEquals(arrList.get(0).getType(),var3);

	}
	
	@Test
	public void testUndo() {
		AddTaskCommand var0 = new AddTaskCommand(arrList);
		String var1 = "Task 1";
		Date var2 = utilDate;
		String var3 = "Complex";
		String var4 = "Frequency";
		var0.execute(var1, var2, var3, var4);
		var0.undo();
		assertEquals(arrList.size(),0);
	}
	
	@Test
	public void testRedo() {
		AddTaskCommand var0 = new AddTaskCommand(arrList);
		String var1 = "Task 1";
		Date var2 = utilDate;
		String var3 = "Single";
		String var4 = "Frequency";
		var0.execute(var1, var2, var3, var4);
		var0.undo();
		var0.redo();
		assertEquals(arrList.size(),1);
		assertEquals(arrList.get(0).getName(),var1);
		assertEquals(arrList.get(0).getDueDate(),var2);
		assertEquals(arrList.get(0).getType(),var3);
		
	}
}